inspector: Support editing interned string properties
authorMatthias Clasen <mclasen@redhat.com>
Tue, 27 Oct 2015 03:38:05 +0000 (23:38 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 27 Oct 2015 03:39:51 +0000 (23:39 -0400)
Sadly, interned string properties cannot be handled generically
at all - GObject insists on inserting a strcpy in any attempt
to set a string property with generic api, destroying the
internedness of the string.

Therefore, we have to special-case GtkCssNode in the property
editor code :-(

gtk/inspector/prop-editor.c

index c6a70a988c049ba2f5cc39f31f97ddbdb3dc65cc..b014dba5cacffbc0c684ec828088213f9afa4761 100644 (file)
@@ -42,6 +42,7 @@
 #include "gtksettingsprivate.h"
 #include "gtktogglebutton.h"
 #include "gtkwidgetprivate.h"
+#include "gtkcssnodeprivate.h"
 
 struct _GtkInspectorPropEditorPrivate
 {
@@ -393,6 +394,18 @@ string_modified (GtkEntry *entry, ObjectProperty *p)
   g_value_unset (&val);
 }
 
+static void
+intern_string_modified (GtkEntry *entry, ObjectProperty *p)
+{
+  const gchar *s;
+
+  s = g_intern_string (gtk_entry_get_text (entry));
+  if (g_str_equal (p->spec->name, "id"))
+    gtk_css_node_set_id (GTK_CSS_NODE (p->obj), s);
+  else if (g_str_equal (p->spec->name, "name"))
+    gtk_css_node_set_name (GTK_CSS_NODE (p->obj), s);
+}
+
 static void
 string_changed (GObject *object, GParamSpec *pspec, gpointer data)
 {
@@ -922,8 +935,12 @@ property_editor (GObject                *object,
                                  G_CALLBACK (string_changed),
                                  prop_edit, G_OBJECT (prop_edit));
 
-      connect_controller (G_OBJECT (prop_edit), "changed",
-                          object, spec, G_CALLBACK (string_modified));
+      if (GTK_IS_CSS_NODE (object))
+        connect_controller (G_OBJECT (prop_edit), "changed",
+                            object, spec, G_CALLBACK (intern_string_modified));
+      else
+        connect_controller (G_OBJECT (prop_edit), "changed",
+                            object, spec, G_CALLBACK (string_modified));
     }
   else if (type == G_TYPE_PARAM_BOOLEAN)
     {